package com.lry.sso.service.service.impl;

import java.util.List;

import com.lry.sso.data.dao.SysUserMapper;
import com.lry.sso.data.pojo.SysUser;
import com.lry.sso.service.annotation.Retry;
import com.lry.sso.service.exception.RetryException;
import com.lry.sso.service.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 *
 * @author 李瑞益
 * @date 2019/9/1
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser getByUsername(String username) {
       return sysUserMapper.getByUsername(username);
    }

    @Override
    public int insertUser(SysUser user) {
        return sysUserMapper.insert(user);
    }


    @Override
    public SysUser getById(Long id) {
        return sysUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(SysUser user) {
        return sysUserMapper.updateByPrimaryKeySelective(user);
    }


    @Override
    public int updateTest(String name,Long id) {
        SysUser u = sysUserMapper.selectByPrimaryKey(id);
        u.setUsername(name);
        int i = sysUserMapper.updateByPrimaryKeySelective(u);
        return i;
    }

    @Transactional(isolation = Isolation.READ_COMMITTED)
    @Override
    public int updateTest2(String name,Long id) {
        List<SysUser> list = sysUserMapper.getAll(id);
        SysUser u = new SysUser();
        u.setUsername(name);
        u.setId(3L);
        return sysUserMapper.updateByPrimaryKeySelective(u);
    }
}
